home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ARASAN_S.ZIP / ATTACKS.H < prev    next >
C/C++ Source or Header  |  1994-08-14  |  2KB  |  94 lines

  1. // Copyright 1992 by Jon Dart.  All Rights Reserved.
  2.  
  3. #ifndef _ATTACKS_H
  4. #define _ATTACKS_H
  5.  
  6. #include "types.h"
  7. #include "color.h"
  8. #include "piece.h"
  9. #include "square.h"
  10. #include "atckentr.h"
  11.  
  12. class Board;
  13.  
  14. class Attacks
  15. {
  16.    // Maintains information about which pieces attack which squares
  17.    // on the chessboard.  This information is updated after every move.      
  18.  
  19.    public:
  20.        
  21.    Attacks();
  22.  
  23. #if !defined(WINDOWS) && defined(DEBUG_ATTACKS)
  24.    void dump_attacks();
  25. #endif
  26.     
  27.    void compute_attacks( const Board &board, const ColorType side );
  28.    // Calculate initial attack info for "board".  This is fairly
  29.    // expensive.       
  30.  
  31.    void add_attacks( const Board &board, 
  32.        const Square &sq, const ColorType side);
  33.  
  34.    void add_discovered_attacks( const Board &board,
  35.        const Square &sq, const Square &dest_square );
  36.  
  37.    void remove_discovered_attacks( const Board &board,
  38.        const Square &sq, 
  39.        const Square &start_square);
  40.  
  41.    void remove_attacks( const Board &board,
  42.        const Square &sq, const ColorType side);
  43.  
  44.    void clear();
  45.  
  46.    Boolean any_attacks( const Square &sq, const ColorType side) const
  47.    {
  48.        return (sq.OnBoard()) ? my_attacks[sq][side].any_attacks() : 0;
  49.    }
  50.        
  51.    unsigned num_attacks( const Square &sq, const ColorType side ) const
  52.    {
  53.        return (sq.OnBoard()) ? my_attacks[sq][side].num_attacks() : 0;
  54.    }
  55.  
  56.    unsigned pawn_attacks( const Square &sq, const ColorType side) const;
  57.    // returns the number of pawns of 'side' attacking or defending
  58.    // 'sq'.
  59.        
  60.    const Attack_Entry &get_attacks( const Square sq, const ColorType side ) const
  61.    { 
  62.         return my_attacks[sq][side];       
  63.    }
  64.    
  65.    void set_attacks( const Attack_Entry &e, const int indx, const ColorType side)
  66.    {
  67.        my_attacks[indx][side] = e;
  68.    }
  69.    
  70. #ifdef DEBUG_ATTACKS
  71.    int operator == (const Attacks &) const;
  72. #endif
  73.    
  74.    private:
  75.  
  76.    void add_attack( const Square &sq, const Piece &p, 
  77.        const ColorType side)
  78.    {
  79.        my_attacks[sq][side].add_attack(p.Type());
  80.    }
  81.  
  82.    void remove_attack( const Square &sq, const Piece &p,
  83.        const ColorType side)
  84.    {
  85.        my_attacks[sq][side].remove_attack(p.Type());
  86.    }
  87.    
  88.    Attack_Entry my_attacks[64][2]; // attack info for each square
  89.  
  90. };
  91.  
  92. #endif
  93.  
  94.